<?php
if ( !defined('IN_ADMINCP') || !defined('IN_SEC') ){
	exit('Access Denied.');
}

if( is_post() ){
	set_time_limit(0);
	if( $_G['gp_uploadfile'] ){
		$filesdata = explode(',', trim($_G['gp_uploadfile']));
		$type = $filesdata[0];
		$type = str_replace(array('data:image/', ';base64'), '', $type);
		if( in_array($type, array('gif', 'jpg', 'png', 'jpeg'), true) ){
			$filedata = base64_decode($filesdata[1]);
			$filename = 'heivr-edm-' . date('YmdHis') . '.' . $type;
			$uploadfile =  '/static/edm/market/' . $filename;
			file_put_contents(APP_PATH . $uploadfile, $filedata);
			jsonp('http://edm.heivr.com/market/' . $filename);
		}
		jsonp('fail');
		die;
	}
	$subject = $_G['gp_subject'] ? ($_G['gp_subject']) : $admincp->cpmsg('请输入标题');
	$label = $_G['gp_label'] ? ($_G['gp_label']) : '';
	$content = $_G['gp_content'] ? ($_G['gp_content']) : $admincp->cpmsg('请输入内容');
	$to = $_G['gp_to'];

	$sends = array();
	
	$tos = explode(';', $to);
	$sent = 0;
	foreach( $tos as $k => $v ){
		if( is_email($v) ){
			$sent++;
			CloudMail::HTTP($v, $subject, $content, $label);
		}
	}
	jsonp($sent);
//	$admincp->cpmsg('共发送' . $sent . '封邮件');
}



?>